<?php
/**
 * 广告新增修改
 * User: hgq
 * Date: 2016/7/8 0008
 * Time: 上午9:35
 */
use yii\helpers\Url;

?>
<script type="application/javascript">

    var to_institution;
    $(function () {

        var to_institution_list =  <?= json_encode($institutions_list) ?>;
        to_institution = $('#to_institution').treeAutocomplete({
            defaultText: '机构',
            source: to_institution_list,
            onSelected: function (element) {
                var to_institution_code = element.getValue();
                $("#edit_institution_code").val(to_institution_code);
            }
        });

        <?php
        if($institution_code != ''){
        ?>
        to_institution.setValue('<?=$institution_code?>');
        <?php
        }
        ?>


    });
</script>
<div>
    <?php
    if ($detail != null && $detail != '') {
        ?>
        <form class="form-horizontal adminex-form" id="modaledit_submit_form" method="post"
              enctype="multipart/form-data"
              action="ad-save" target="upload_exec_target">
            <div class="form-group">
                <input type="hidden" id="edit_id" name="edit_id" class="form-control" value="<?= $detail["id"] ?>"
                       readonly>
                <input type="hidden" id="edit_institution_code" name="edit_institution_code" class="form-control"
                       value="<?= $detail["institution_code"] ?>" readonly>

                <label class="col-lg-3 col-sm-3 control-label">机构名称：</label>
                <div class="col-lg-9">
                    <input type="text" id="edit_institution_name" name="edit_institution_name" class="form-control"
                           value="<?= $detail["institution_name"] ?>" readonly>
                </div>

            </div>
            <div class="form-group">
                <label class="col-lg-3 col-sm-3 control-label">广告名称：</label>
                <div class="col-lg-9">
                    <input type="text" id="edit_name" name="edit_name" class="form-control"
                           value="<?= $detail["name"] ?>">
                </div>
            </div>

            <div class="form-group">
                <label class="col-lg-3 col-sm-3 control-label">所属分类：</label>
                <div class="col-lg-9">
                    <select id="edit_category_id" name="edit_category_id" class="form-control" onchange="">
                        <option value=""></option>
                        <?php
                        if ($category != null && $category != '') {
                            for ($i = 0; $i < count($category); $i++) {
                                ?>
                                <option
                                    value="<?= $category[$i]['id'] ?>" <?php if ($detail["category_id"] == $category[$i]['id']) echo "selected=\"selected\""; ?>><?= $category[$i]['name'] ?></option>
                                <?php
                            }
                        }
                        ?>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-3 col-sm-3 control-label">图片地址：</label>
                <div class="col-lg-9">
                    <input type="text" id="edit_image_url" name="edit_image_url" class="form-control"
                           value="<?= $detail["image_url"] ?>" readOnly="true">
                    <input id="edit_image_file" name="edit_image_file" type="file"/>
                    <img src="<?= $detail["image_url"] ?>" class="col-lg-4" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-3 col-sm-3 control-label">链接地址：</label>
                <div class="col-lg-9">
                    <input type="text" id="edit_link_url" name="edit_link_url" class="form-control"
                           value="<?= $detail["link_url"] ?>">
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-3 col-sm-3 control-label">广告描述：</label>
                <div class="col-lg-9">
                <textarea id="edit_description" name="edit_description" class="form-control"
                          rows="3"><?= $detail["description"] ?></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-3 col-sm-3 control-label">是否显示：</label>
                <div class="col-lg-9">
                    <select id="edit_is_shown" name="edit_is_shown" class="form-control" onchange="">
                        <option value="1" <?php if ($detail["is_shown"] == "1") echo "selected=\"selected\""; ?>>显示
                        </option>
                        <option value="0" <?php if ($detail["is_shown"] == "0") echo "selected=\"selected\""; ?>>不显示
                        </option>
                    </select>
                </div>
            </div>
        </form>
        <iframe id="upload_exec_target" name="upload_exec_target" style="display: none;"></iframe>
        <?php
    } else {
        ?>
        <form class="form-horizontal adminex-form" id="modaledit_submit_form" method="post"
              enctype="multipart/form-data"
              action="ad-save" target="upload_exec_target">
            <div class="form-group">
                <input type="hidden" id="edit_id" name="edit_id" class="form-control" value="" readonly>
                <input type="hidden" id="edit_institution_code" name="edit_institution_code" class="form-control"
                       value="<?= $institution_code ?>" readonly>

                <label class="col-lg-3 col-sm-3 control-label">机构名称：</label>
                <div class="col-lg-9">
                    <div id="to_institution"></div>
                </div>

            </div>

            <div class="form-group">
                <label class="col-lg-3 col-sm-3 control-label">广告名称：</label>
                <div class="col-lg-9">
                    <input type="text" id="edit_name" name="edit_name" class="form-control" value="">
                </div>
            </div>

            <div class="form-group">
                <label class="col-lg-3 col-sm-3 control-label">所属分类：</label>
                <div class="col-lg-9">
                    <select id="edit_category_id" name="edit_category_id" class="form-control"
                            onchange="">
                        <?php
                        if ($category != null && $category != '') {
                            for ($i = 0; $i < count($category); $i++) {
                                ?>
                                <option
                                    value="<?= $category[$i]['id'] ?>"><?= $category[$i]['name'] ?></option>
                                <?php
                            }
                        }
                        ?>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-3 col-sm-3 control-label">图片地址：</label>
                <div class="col-lg-9">
                    <input type="text" id="edit_image_url" name="edit_image_url" class="form-control"
                           readOnly="true">
                    <input id="edit_image_file" name="edit_image_file" type="file"/>
                    <img src="<?= $detail["image_url"] ?>" class="col-lg-4" />
                </div>
            </div>

            <div class="form-group">
                <label class="col-lg-3 col-sm-3 control-label">链接地址：</label>
                <div class="col-lg-9">
                    <input type="text" id="edit_link_url" name="edit_link_url" class="form-control">
                </div>
            </div>

            <div class="form-group">
                <label class="col-lg-3 col-sm-3 control-label">广告描述：</label>
                <div class="col-lg-9">
                <textarea id="edit_description" name="edit_description" class="form-control"
                          rows="3"></textarea>
                </div>
            </div>

            <div class="form-group">
                <label class="col-lg-3 col-sm-3 control-label">是否显示：</label>
                <div class="col-lg-9">
                    <select id="edit_is_shown" name="edit_is_shown" class="form-control" onchange="">
                        <option value="1" selected="selected">显示</option>
                        <option value="0">不显示</option>
                    </select>
                </div>
            </div>
        </form>
        <iframe id="upload_exec_target" name="upload_exec_target" style="display: none;"></iframe>
        <?php
    }
    ?>
</div>

